/****************************************************************************
 * Copyright (C) 2009-2010 SciTouch LLC
 * 
 * This file is part of Indigo toolkit.
 * 
 * This file may be distributed and/or modified under the terms of the
 * GNU General Public License version 3 as published by the Free Software
 * Foundation and appearing in the file LICENSE.GPL included in the
 * packaging of this file.
 * 
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 ***************************************************************************/

#ifndef __smiles_loader__
#define __smiles_loader__

#include "base_cpp/exception.h"
#include "molecule/molecule.h"

class Scanner;
class Molecule;
class GraphHighlighting;

class SmilesLoader
{
public:
   DEF_ERROR("SMILES loader");

   SmilesLoader (Scanner &scanner);

   void loadMolecule (Molecule &mol, bool query);

   Array<int> * reaction_atom_mapping;

   GraphHighlighting * highlighting;

   bool inside_rsmiles;
   void checkQueryAtoms (const Molecule &mol );

protected:
   struct _AtomDesc
   {
      int label;
      int isotope;
      int charge;
      int hydrogens;
      int chirality;
      int aromatic;
      int aam;

      QueryAtom query;
   };

   struct _BondDesc
   {
      int beg;
      int end;
      int type;
      int dir; // 0 -- undirected; 1 -- goes 'up' from beg to end, 2 -- goes 'down'

      QueryBond query;
   };

   struct _CycleDesc
   {
      void clear ()
      {
         beg = -1;
         pending_bond = -1;
      }

      int beg;
      int pending_bond;
   };

   Scanner &_scanner;

   TL_CP_DECL(Array<_AtomDesc>, _atoms);
   TL_CP_DECL(Array<_BondDesc>, _bonds);
   TL_CP_DECL(Array<Edge>, _closures);
   

   void _loadMolecule (Molecule &mol, bool query);

   void _calcStereocenters (Molecule &mol);
   void _calcCisTrans (Molecule &mol, bool query);
   void _readOtherStuff (Molecule &mol, bool query);

private:
   SmilesLoader (const SmilesLoader &); // no implicit copy
};

#endif
